<?
require_once("../config/dbconn.php");require_once("../config/powercls.php");require_once("../config/pagecls.php");
if($action=='islock'){
	$sqlhy="select * from {$db_prefix}users where id='$id'";
	$rshy=$db->get_one($sqlhy);
  
	if($action=='fhstata'){
  $sqlhy="select * from {$db_prefix}users where id='$id'";
  $rshy=$db->get_one($sqlhy);
  
  if($rshy["fhstata"]==0)
  {
    $sqlgx="update {$db_prefix}users set fhstata=1 where id='$id'";
  }
  else
  {
    $sqlgx="update {$db_prefix}users set fhstata=0 where id='$id'";
  }
  $db->query($sqlgx);

  echo "<script>location.href='user_lst.php?pageno={$pageno}';</script>";exit();
}

	if($rshy["islock"]==0)
	{
		$sqlgx="update {$db_prefix}users set islock=1 where id='$id'";
	}
	else
	{
		$sqlgx="update {$db_prefix}users set islock=0 where id='$id'";
	}
	$db->query($sqlgx);

	echo "<script>location.href='user_lst.php?pageno={$pageno}';</script>";exit();
}
if($action=='ft_isend'){
	$sqlhy="select * from {$db_prefix}users where id='$id'";
	$rshy=$db->get_one($sqlhy);
	
	if($rshy["ft_isend"]==0)
	{
		$sqlgx="update {$db_prefix}users set ft_isend=1 where id='$id'";
	}
	else
	{
		$sqlgx="update {$db_prefix}users set ft_isend=0 where id='$id'";
	}
	$db->query($sqlgx);

	echo "<script>location.href='user_lst.php?pageno={$pageno}';</script>";exit();
}
if($action=='fhstata'){
  $sqlhy="select * from {$db_prefix}users where id='$id'";
  $rshy=$db->get_one($sqlhy);
  
  if($rshy["fhstata"]==0)
  {
    $sqlgx="update {$db_prefix}users set fhstata=1 where id='$id'";
  }
  else
  {
    $sqlgx="update {$db_prefix}users set fhstata=0 where id='$id'";
  }
  $db->query($sqlgx);

  echo "<script>location.href='user_lst.php?pageno={$pageno}';</script>";exit();
}

if($action=='del'){
	$msg='';
	$sql="select * from {$db_prefix}users where id='$id'";
	$rs=$db->get_one($sql);
	$regpv=$rs['regpv'];$regnum=$rs['regnum'];$regtime=$rs['confirmtime'];$regpos=$rs['pos'];
	$sqltj="select count(id) as c from {$db_prefix}users where tjuser='".$rs['username']."'";
	$rstj=$db->get_one($sqltj);
	if (intval($rstj['c'])>0){
		$msg.="有推荐的会员。不能删除\\n";
	}
	if ($msg!=''){
		echo "<script>alert('$msg');history.back();</script>";exit();
	}
	$sqlgl="select count(id) as c from {$db_prefix}users where gluser='".$rs['username']."'";
	$rsgl=$db->get_one($sqlgl);
	if (intval($rsgl['c'])>0){
		$msg.="有管理的会员。不能删除\\n";
	}
	if ($msg!=''){
		echo "<script>alert('$msg');history.back();</script>";exit();
	}
	
	//删除会员的关系表
	$db->delete("{$db_prefix}tjgx","userid='$id'");	
	$db->delete("{$db_prefix}glgx","userid='$id'");	
	//删除业绩表
	$db->delete("{$db_prefix}hyyj","userid='$id'");
	//删除会员
	$db->delete("{$db_prefix}users","id='$id'");
	
	echo "<script>location.href='user_lst.php?pageno={$pageno}';</script>";exit();
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	
}
td{
font-size:12px;
}
-->
</style>

<link href="images/skin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="17" height="29" valign="top" background="images/mail_leftbg.gif"><img src="images/left-top-right.gif" width="17" height="29" /></td>
    <td width="935" height="29" valign="top" background="images/content-bg.gif"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
      <tr>
        <td height="31"><div class="titlebt">会员管理</div></td>
      </tr>
    </table></td>
    <td width="16" valign="top" background="images/mail_rightbg.gif"><img src="images/nav-right-bg.gif" width="16" height="29" /></td>
  </tr>
  <tr>
    <td height="71" valign="middle" background="images/mail_leftbg.gif">&nbsp;</td>
    <td valign="top" bgcolor="#F7F8F9"><table width="100%" height="138" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td height="13" valign="top">&nbsp;</td>
      </tr>
      <tr>
        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="nowtable">
                <tr>
                  <td align="center" class="left_bt2">
<form name="form1" method="post" action="?action=query">
	编号：
	  <input name="hyid" type="text" id="hyid" size="5">
	  用户名：
	  <label>
      <input name="username" type="text" id="username" size="5">
      </label>
		姓名：
	  <label>
      <input name="nickname" type="text" id="nickname" size="5">
      </label>
      手机号：
	  <label>
      <input name="mobile" type="text" id="mobile" size="5">
      </label>

	推荐人：
  <label>
  <input name="tjuser" type="text" id="tjuser" size="5">
  </label>
	管理人：
	<input name="gluser" type="text" id="gluser" size="5">
	
	区位：<select name="pos" id="pos" >
                    <option value="">全部</option>
                    <?
					    foreach($sysposary as $k1=>$v1){
							echo "<option value='{$k1}'";
							if ($pos==$k1) echo " selected";
							echo ">{$v1}</option>";
						  }
					   ?>
                  </select>

    <label></label>
  <label>
  <input type="submit" name="Submit" value="查询">
  </label>
                        </form></td>
                </tr>
              </table></td>
            </tr>
            <tr>
              <td height="30"><table width="100%" height="60" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
                <tr>
                  <td height="30" align="center" bgcolor="#f2f2f2" >编号</td>
                  <td align="center" bgcolor="#f2f2f2" >用户名</td>
                  <td align="center" bgcolor="#f2f2f2" >姓名</td>
                  <td align="center" bgcolor="#f2f2f2" >级别</td>
                  <td align="center" bgcolor="#f2f2f2" >推荐人</td>
                  <td align="center" bgcolor="#f2f2f2" >管理人</td>
                  <td align="center" bgcolor="#f2f2f2" >区位</td>
                  <td align="center" bgcolor="#f2f2f2" >左区业绩</td>
                  <td align="center" bgcolor="#f2f2f2" >右区业绩</td>
                  <td align="center" bgcolor="#f2f2f2" >资产钱包</td>
                  <td align="center" bgcolor="#f2f2f2" >释放钱包</td>
                  <td align="center" bgcolor="#f2f2f2" >智能钱包</td>
                  <td align="center" bgcolor="#f2f2f2" >算力钱包</td>
                  <td align="center" bgcolor="#f2f2f2" >交易钱包</td>
                  <td align="center" bgcolor="#f2f2f2" >冻结钱包</td>
                  <!-- <td align="center" bgcolor="#f2f2f2" >总奖金</td> -->
                  <td align="center" bgcolor="#f2f2f2" >注册时间</td>
                  <td height="30" align="center" bgcolor="#f2f2f2" >网络图</td>
                  <td height="30" align="center" bgcolor="#f2f2f2" >冻结</td>
                  <!-- <td height="30" align="center" bgcolor="#f2f2f2" >复投</td> -->
                  <td height="30" align="center" bgcolor="#f2f2f2" >操作</td>
                  </tr>
				  <tbody bgcolor="#FFFFFF">
	 <?
  $query='';

  
  if ($action=='query'){
  	if (trim($hyid)!='') $query.=" and id ='".trim($hyid)."'";	
	if (trim($username)!='') $query.=" and username ='".trim($username)."'";	
	if (trim($nickname)!='') $query.=" and nickname ='".trim($nickname)."'";	
	if (trim($mobile)!='') $query.=" and mobile ='".trim($mobile)."'";	
	if (trim($tjuser)!='') $query.=" and tjuser ='".trim($tjuser)."'";
	if (trim($gluser)!='') $query.=" and gluser ='".trim($gluser)."'";
	if (trim($pos)!='') $query.=" and pos ='".trim($pos)."'";
  }
  
  $sql="select count(id) as c  from {$db_prefix}users where 1";
  if ($query!='') $sql.=$query;
  $rs=$db->get_one($sql);
  $page=new pagecls(20,intval($rs['c']));
  $sql="select * from {$db_prefix}users where 1";
  if ($query!='') $sql.=$query;
  $sql.=" order by id asc limit {$page->pastnum},{$page->pagesize}";
  $result=$db->query($sql);
  while($rs=$db->fetch_array($result)){
  ?>
                <tr>
                  <td align="center"><?=$rs['id']?></td>
                  <td align="center"><?=$rs['username']?></td>
                  <td align="center">
                    <?=$rs['nickname']?>                  </td>
                  <td align="center"><?=$hyrankary1[$rs['rank']]?></td>
                  <td align="center" ><?=$rs['tjuser']?></td>
                  <td align="center" ><?=$rs['gluser']?></td>
                  <td align="center" ><?=$sysposary[$rs['pos']]?></td>
                  <td align="center" >
                    <?
                    $gl_left = $db->get_one("select id,username from {$db_prefix}users where gluser='".$rs['username']."' and pos =1");
                        if(!empty($gl_left)){
                          $left_id = $gl_left['id'];
                          $left_username = $gl_left['username'];
                          //左区业绩
                          $left_yeji = $db->get_one("select sum(price) as c1, sum(sfprice) as c2 from {$db_prefix}users where FIND_IN_SET({$left_id},glstr)or id={$left_id}");
                        if(!empty($left_yeji)){
                            $leftall_yeji = $left_yeji['c1']+$left_yeji['c2'];
                            echo $leftall_yeji;
                        }
                    }else{
                      echo 0;
                    }
                    ?>
                    
                  </td>
                <td align="center" >
                    <?
                    $gl_right = $db->get_one("select id,username from {$db_prefix}users where gluser='".$rs['username']."' and pos =2");
                    if(!empty($gl_right)){
                $right_id = $gl_right['id'];
                $right_username = $gl_right['username'];
                //右区业绩
                $right_yeji = $db->get_one("select sum(price) as c1, sum(sfprice) as c2 from {$db_prefix}users where FIND_IN_SET({$right_id},glstr)or id={$right_id}");
                if(!empty($right_yeji)){
                    $rightall_yeji = $right_yeji['c1']+$right_yeji['c2'];
                    echo $rightall_yeji;
                }
            }else{
              echo 0;
            }
                    ?>
                    
                  </td>
                  <td align="center" ><?=$rs['price']?></td>
                  <td align="center" ><?=$rs['sfprice']?></td>
                  <td align="center" ><?=$rs['znprice']?></td>
                  <td align="center" ><?=$rs['slprice']?></td>
                  <td align="center" ><?=$rs['jyprice']?></td>
                  <td align="center" ><?=$rs['djprice']?></td>
                  <!-- <td align="center" ><?=$rs['znprice']+$rs['slprice']?></td> -->
                  <td align="center" ><?=date("Y-m-d H:i:s",$rs['regtime'])?></td>
                   <td height="30" align="center" >
                    <a href="?action=fhstata&id=<?=$rs['id']?>&pageno=<?=$page->pageno?>" onClick="return confirm('确定改变显示状态吗?')">
                  <? if ($rs['fhstata']==1) echo "已显示";else echo "未显示";?></a>
                  </td>
                  <td height="30" align="center" >
                    <a href="?action=islock&id=<?=$rs['id']?>&pageno=<?=$page->pageno?>" onClick="return confirm('确定改变冻结状态吗?')">
                  <? if ($rs['islock']==1) echo "已冻结";else echo "未冻结";?></a>
                  </td>
                  <!-- <td height="30" align="center" >
                  <a href="?action=ft_isend&id=<?=$rs['id']?>&pageno=<?=$page->pageno?>" onClick="return confirm('确定改变收益状态吗?')"><? if ($rs['ft_isend']==1) echo "已锁定";else echo "未锁定";?></a>
                  </td> -->
                  <td height="30" align="center" >
                  <a href="user_view.php?id=<?=$rs['id']?>&pageno=<?=$page->pageno?>">查看</a> | <a href="user_edit.php?id=<?=$rs['id']?>&pageno=<?=$page->pageno?>">修改</a> | <a href="?action=del&id=<?=$rs['id']?>&pageno=<?=$page->pageno?>" onClick="return confirm('确定要删除会员?')">删除</a></td>
                  </tr>
 <?
  }
  $db->free_result($result);
  ?>
  </tbody>
              </table></td>
            </tr>
            
            <tr>
              <td height="30">&nbsp;</td>
            </tr>
            <tr>
              <td height="30" align="right"><form action="?<?=$page->url?>" method="post" style="margin:0px ; padding:0px;">每页<?=$page->pagesize?>条 第<?=$page->pageno?>/<?=$page->pagenum?>页 共<?=$page->recnum?>条 <a href='?<?=$page->url?>1'><img src="image1/first.gif" border="0"></a>   <a href='?<?=$page->url.($page->pageno-1)?>'><img src="image1/back.gif" border="0"></a>  <a href='?<?=$page->url.($page->pageno+1)?>'><img src="image1/next.gif" border="0"></a>   <a href='?<?=$page->url.$page->pagenum?>'><img src="image1/last.gif" border="0"></a> 
			转到：<input name="pageno" value="" size="1" type="text"> <input name="gobg" value="go" type="submit">
			  </form></td>
              </tr>
            <tr>
              <td height="30"><strong>统计:资产钱包累计<?
			  $sqlgy="select sum(price) as c,sum(sfprice) as c0,sum(znprice) as c1,sum(slprice) as c2,sum(jyprice) as c3 from {$db_prefix}users where state=1";
			  $rsgy=$db->get_one($sqlgy);
			  echo floatval($rsgy['c']);
			  ?>
                ， 释放钱包累计
                <?=floatval($rsgy['c0']);?>
                ，智能钱包累计
                <?=floatval($rsgy['c1']);?>
                ，算力钱包累计
                <?=floatval($rsgy['c2']);?>
                ，交易钱包累计
                <?=floatval($rsgy['c3']);?>
              </strong></td>
            </tr>
          </table></td>
      </tr>
    </table></td>
    <td background="images/mail_rightbg.gif">&nbsp;</td>
  </tr>
  <tr>
    <td valign="middle" background="images/mail_leftbg.gif"><img src="images/buttom_left2.gif" width="17" height="17" /></td>
      <td height="17" valign="top" background="images/buttom_bgs.gif"><img src="images/buttom_bgs.gif" width="17" height="17" /></td>
    <td background="images/mail_rightbg.gif"><img src="images/buttom_right2.gif" width="16" height="17" /></td>
  </tr>
</table>

</body>
</html>
